﻿// 2024/12/18: 首个版本
// 2025/4/8: 修正yaw angle解析
// 2025/8/4: 不使用cat宏

#ifndef POINT_CLOUD_V2_H
#define POINT_CLOUD_V2_H

#include "spadas.h"

namespace point_cloud_v2
{
	using namespace spadas;

	struct PointCloudData
	{
		UInt pointCount; // 点个数
		FloatMat points; // Coordinates of points, the size of array is Nx3, while N is number of points, 3 means x(front),y(left),z(up), in meters / 各点坐标，数组尺寸为Nx3，N为个数，3分别为x(前),y(左),z(上)轴坐标，单位为米
		Array<Float> intensities; // Intensity of points, in percentages, can be empty / 各点强度，单位为%，可为空
		Array<ColorRGB> colors; // Color of points, can be empty / 各点颜色，可为空
		Array<Word> laserIDs; // Laser ID of points, can be empty (For example, from bottom to top, ID of 32 line lidar are 0~31) / 各点的激光束ID，可为空（如32线雷达从下往上ID分别为0~31）
		Array<Float> timeOffsets; // Time offset (relative to sample's timestamp) of points, in microseconds, can be empty / 各点相对于样本时间偏置，单位微秒，可为空
		Array<Float> yawAngles; // Yaw angle of points, in degrees, can be empty / 各点横摆角，单位度，可为空
		Array<Byte> mirrorIDs; // Mirror ID of points, can be empty / 各点镜面ID，可为空
		Map<IntKey, Array<Byte> > byteValues; // Dictionary for byte values. The key is field ID, the value is byte values / Byte值字典，键为字段ID，值为Byte值
		Map<IntKey, Array<Short> > shortValues; // Dictionary for short values. The key is field ID, the value is short values / Short值字典，键为字段ID，值为Short值
		Map<IntKey, Array<Float> > floatValues; // Dictionary for float values. The key is field ID, the value is float values / Float值字典，键为字段ID，值为Float值

		PointCloudData()
		{
			pointCount = 0;
		}
	};

	class PointCloud : public Object<class PointCloudVars>
	{
	public:
		SPADAS_TYPE("point_cloud_v2.PointCloud")

		PointCloud();
		FullTimestamp& timestamp();
		PointCloudData *operator ->();

		static String getProtocolName(UInt channel);
		SessionMatrixSample toMatrixSample();

		static Array<String> getProtocolNames(UInt channel);
		Bool fromMatrixSample(String protocol, SessionMatrixSample matrixSample);
	};
}

#endif